package com.ruicar.afs.cloud.basic.common.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.basic.common.condition.BasicMqErrorLogCondition;
import com.ruicar.afs.cloud.basic.common.entity.BasicMqErrorLog;
import com.ruicar.afs.cloud.basic.common.service.BasicMqErrorLogService;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.util.EmptyUtils;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: 查询mq报错展示信息
 */
@Slf4j
@RestController
@RequestMapping("/mqError")
@AllArgsConstructor
public class BasicMqErrorLogController {

    private BasicMqErrorLogService basicMqErrorLogService;

    @ApiOperation(value = "mq错误日志分页列表查询")
    @PostMapping("/getMqErrorList")
    public IResponse<List<BasicMqErrorLog>> getMqErrorList(@RequestBody QueryCondition<BasicMqErrorLogCondition> basicMqErrorLog) {
        IPage<List<BasicMqErrorLog>> list = basicMqErrorLogService.page(new Page(basicMqErrorLog.getPageNumber(), basicMqErrorLog.getPageSize()), Wrappers.<BasicMqErrorLog>lambdaQuery()
                .like(EmptyUtils.isNotEmpty(basicMqErrorLog.getCondition().getContractNo()), BasicMqErrorLog::getContractNo, basicMqErrorLog.getCondition().getContractNo())
                .like(EmptyUtils.isNotEmpty(basicMqErrorLog.getCondition().getApplyNo()), BasicMqErrorLog::getApplyNo, basicMqErrorLog.getCondition().getApplyNo())
                .eq(EmptyUtils.isNotEmpty(basicMqErrorLog.getCondition().getMqBusinessType()), BasicMqErrorLog::getMqBusinessType, basicMqErrorLog.getCondition().getMqBusinessType()));
        return IResponse.success(list);
    }
}
